package math;

import java.util.Arrays;

public class Averagers{

	public interface Averager {
		String getName();
		double getAverage(double[] points);
	}
	
	static public class Median implements Averager {

		@Override
		public String getName() {
			return "Median";
		}

		@Override
		public double getAverage(double[] a) {
			double[] b = new double[a.length];
			System.arraycopy(a, 0, b, 0, b.length);
	    	Arrays.sort(b);
	    	if (b.length % 2 == 0) {
	    		return (b[(b.length / 2) - 1] + b[b.length / 2]) / 2.0;
	    	} else {
	    		return b[b.length / 2];
	    	}
		}
	}
	
	static public class Mean implements Averager {

		public String getName() {
			return "Mean";
		}

		@Override
		public double getAverage(double[] a) {
			double ret = 0;
			for (double d : a) {
				ret += d;
			}
			return ret / a.length;
		}
	}
}
